package com.gandong8.derby.core.aop;

import com.gandong8.derby.core.util.RequestUtil;
import com.gandong8.derby.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 获取输入输出日志
 * @author xiaoyutou
 */
@Component
@Aspect
@Slf4j
public class RequestLog  {

    @Autowired
    UserService userService;

    @Around("execution( * com.gandong8.derby.controller.*.*(..))")
    public Object handle(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();
        //log.info("begin_request:ip={},path={},get={},post={}", RequestUtil.getIp(), RequestUtil.getPath(),RequestUtil.getParameters(),joinPoint.getArgs());
        userService.userLogSave();
        Object result = joinPoint.proceed();
        Long pass = System.currentTimeMillis() - startTime;
        log.info("end_request:path={},time={}", RequestUtil.getPath(), pass);
        return result;
    }


}

